package com.hyxt.DTO;

import io.netty.channel.Channel;

import static com.hyxt.DTO.ServerHandler.channleMap;
import static com.hyxt.DTO.ServerHandler.signMap;

/**
 * @author shenp
 * @version v1.0
 * @Description:终端链路管理类
 * @Date: Create in 17:48 2017/11/21
 * @Modifide By:
 **/
public class TermianaUtil {
    /**
     *
     * 根据唯一标识获取ip+port
     * @param sign
     * @return
     */
    public static String findIpAndPort(String sign){
        if (signIsOrNot(sign)){
            return signMap.get(sign);
        }
        else {
            return "";
        }
    }

    /**
     * 根据ip+port获取链路
     * @param ipAndPort
     * @return
     */
    public static Channel findChannel(String ipAndPort){
        if(channelIsOrNot(ipAndPort)){
            return channleMap.get(ipAndPort);
        }
        else {
            return null;
        }
    }

    /**
     * 判断ip+port是否存在
     * @param sign
     * @return
     */
    public static boolean signIsOrNot(String sign){
        if (signMap.containsKey(sign)){
           return true;
        }else {
            return false;
        }
    }

    /**
     * 判断链路是否存在
     * @param ipAndPort
     * @return
     */
    public static boolean channelIsOrNot(String ipAndPort){
        if(channleMap.containsKey(ipAndPort)){
            return true;
        }else{
            return false;
        }
    }

}
